﻿using System;
using System.Web.UI.WebControls;
using movies;

public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string logout = (string)Request.Params["logout"];
        string islogin = (string)Request.Params["login"];


        if ( logout != null && logout.Equals("true")) 
        {
            Session.Clear();
        }

        if (Session["Customer"] != null)
        {
            this.login.Visible = false;
        }
        if (islogin != null && islogin.Equals("false"))
        {
            this.lblLogReq.Visible = true;
        }

    }

   /// <summary>
   /// Method authenticates the username and password entered in the login box
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="e"></param>
     
    protected void login_Authenticate(object sender, AuthenticateEventArgs e)
    {
        
        bool bauthenticated = false;

        bauthenticated =  Master.isUserValid((string)this.login.UserName, (string)this.login.Password);
        
        //depedning on authentication set the web ui control to true or false
        if (bauthenticated)
        {
            e.Authenticated = true;
        }
        else
        {
            e.Authenticated = false;
        }
        

    }
}
